<?php

class LMSBookRequestModel
{
    private $mConnection;
    private $mDatabase;
	private $mQuery;
	private $mResult;
	
	function __construct()
	{
		//initialization can be done here
		$this->mConnection = null;
    	$this->mDatabase = null;
	 	$this->mQuery = null;
	 	$this->mResult = null;
	}
	
	/** method or function name
	* description
	* parameters 
	* return type
	*/
	
    public function connectDatabase()
    {
		$this->mConnection = mysql_connect("localhost", "root", "") or die ("could not connect");
		$this->mDatabase = mysql_select_db("lms_database", $this->mConnection) or die("could not connect with database");
    }
	
	public function getBookRequestModel()
	{
		$this->connectDatabase();
		$this->mQuery = "SELECT * FROM lms_book_request_table";
		$this->mResult = mysql_query($this->mQuery) or die("could not get data from table");
		return $this->mResult;
	}
	
	public function setBookRequestModel($data)
	{   
		$this->connectDatabase();
		$this->mQuery = "SELECT * FROM lms_library_books_table WHERE bookID=".$data;
		$this->mResult = mysql_query($this->mQuery) or die("could not get data from table");
		$row = mysql_fetch_array($this->mResult);
		$this->mQuery = "INSERT INTO lms_book_request_table VALUES('".$_SESSION['ID']."',".$row['bookID'].",'".$row['bookName']."','".$row['authorName']."',".$row['editionNumber'].",'".$row['publication']."',"."NULL,"."NULL,"."0)";
		mysql_query($this->mQuery) or die("could not get data from table");
	}
	
	public function updateBookRequestModel($issueDate,$returnDate,$bookID)
	{
		$this->connectDatabase();
		$this->mQuery = "UPDATE  lms_book_request_table SET issuedDate='".$issueDate."',"."returnDate='".$returnDate."',Flag=1 "."WHERE bookID=".$bookID;
		echo $this->mQuery;
		mysql_query($this->mQuery) or die("could not get data from table");
	}
}